\defaulted debt\JPErevision\response_xav\referencemodel\barg\codeoutline_barg.f90


LAYOUT OF CODE
\defaulted debt\JPErevision\response_xav
        \referencemodel\barg\refmodelbargEV_v0.f90  version separte tau and a.

        \referencemodel\barg\refmodelbargEV_v1.f90 - version tau=a'/delta

!******************************
! MAIN GLOBAL VARIABLES
!******************************
Params: q0 delta beta sigma

Arrays:
Aj Bj zj nBzero nBneg nAneg nAzero
pinu piz
nnu ntheta nA nB

qqtil qq
HH

vD
vND, locBND, BND_c

vv vv_temp
DEF TT AA

vB_ND vB_D
locaprB_ND tauB_ND


!*********************************************************
! refmodelbargEV_v0.f90 & refmodelbargEV_v1.f90
! main program
!*********************************************************
PROGRAM main
 use mainmodule
    call readinfo
    call allocstuff
    call initstuff
    call stat_distr
    call prices_iter

    call write_inout
    call write_functions

    call simul_paths
    call stochsimul_IRF(ntimeIRF,npathsIRF)

    call calib_bobyqa_case1
    call calib_bobyqa_case2
    call calib_bobyqa_case3
    call calib_bobyqa_case4
    call calib_bobyqa_case5
    call calib_bobyqa_case6
    call calib_bobyqa_case7

module mainmodule
!-------------------------------------
! [1.] READ INFO AND GRIDS
!-------------------------------------
[readinfo]
    call read_grids
    call read_ecpars

[read_grids]
[read_ecpars]
    use tauchen_mod
    call tauchen
[allocstuff]

[initistuff]
    call read_q
    call read_h
    call read_v
    call init_finiteec5
    call init_finiteec6
[init_finiteec5]
[init_finiteec6]
!-------------------------------------
! [2.] READ/WRITE INITIAL CONDITIONS
!-------------------------------------
[read_q]
[write_q]
[read_h]
[write_h]
[read_v]
[write_v]

[stat_distr]

!-------------------------------------
! [3.] SOVEREIGN
!-------------------------------------
[agentD_opt]
    utt
[agentND_opt]
    use interp
    call spline
    call uttND_array_defi
    call vexpND_array_defi

    contains
    [uttND_array_defi]
        utt
    [vexpND_array_defi]
        vvinterp
    <vvinterp>
        lip
        splint
    <uttND_c>
        utt
        lip
        splint
    <vexpND_c>
        vvinterp
    <vvND_c>
        uttND_c
        vexpND_c
    <negat_vvND_c>
        vvND_c

[nobarg_iter]

!-------------------------------------
! [4.] FUNCTIONS FOR SOVEREIGN
!-------------------------------------
<utt_c>
<psi>

!-------------------------------------
! [5.] BARGAINING
!-------------------------------------
[barg_iter]
    call barg_outopt
    call barg_nu1_ND
    call barg_nu1_D
    call barg_nu1
    call barg_nu2_ND
    call barg_nu2_D
    call barg_nu2

[barg_outopt]
    vvinterp_outopt
    contains
    <vvinterp_outopt>
        lip
        splint
[barg_nu1]
[barg_nu1_ND] (for version refmodelbargEV_v0.f90)
     call uttB_ND_array_defi
     call vexpB_ND_array_defi
     call tauB_ND_func_to_arr
     tauB_ND_func
     contains
     [tauB_ND_func_to_arr]
        tauB_ND_func
     <tauB_ND_func>
     [uttB_ND_array_defi]
        utt
        psi
        tauB_ND_func
     [vexpB_ND_array_defi]

[barg_nu1_ND] (for version refmodelbargEV_v1.f90)
     call recov_ND_array_defi
     call uttB_ND_array_defi
     call vexpB_ND_array_defi
     contains
     [recov_ND_array_defi]
     [uttB_ND_array_defi]
        utt
        psi
     [vexpB_ND_array_defi]

[barg_nu1_D]

[barg_nu2]
[barg_nu2_ND] (for version refmodelbargEV_v0.f90)
     call tauB_ND_array_defi
     call aHexpB_ND_array_defi
     contains
     [tauB_ND_array_defi]
        psi
        utt
     [aHexpB_ND_array_defi]

[barg_nu2_ND] (for version refmodelbargEV_v1.f90)
     call tauB_ND_array_defi
     call aHexpB_ND_array_defi
     call val_ND_array_defi
     negat_wB_ND_c
     contains
     <negat_wB_ND_c>
        use interp
        lip
     [tauB_ND_array_defi]
     [val_ND_array_defi]
        psi
        utt
     [aHexpB_ND_array_defi]

[barg_nu2_D]

[barg_nu1_EVshocks]

[barg_nu2_EVshocks]
    use interp
    utt
    psi
    vexp_theta1_c
    contains
        <vexp_theta1_c>
        <vvinterp>

[barg_agentval]
    use interp
    utt
    psi
    vexp_theta1_c
    contains
        <vexp_theta1_c>
        <vvinterp>

[update_agentval]


!-------------------------------------
! [7.] LENDER'S VALUE
!-------------------------------------
[lender_iter]
    use interp
    call spline
    call Hexp_theta0_arr_defi
    splint
    Hexp
    contains
    [Hexp_theta0_arr_defi]
    <Hexp>
        lip
        splint


[lender_theta1_iter] (obsolete)

!-------------------------------------
! [8.] UPDATE PRICES
!-------------------------------------
[updques]
    call write_q

[qqmap]
    use interp
    lip
    call spline
    splint

!-------------------------------------
! [9.] Solve EQUIL PRICES
!-------------------------------------
[prices_iter]
   call updques
   call qqmap
   !call agent_iter
   call agentND_opt
   call agentD_opt
   call nobarg_iter
   call barg_iter
   call barg_agentval
   call update_agentval
   call lender_iter
   !call lender_theta1_iter

!-------------------------------------
! [10.] WRITE IN/OUT FILES
!-------------------------------------
[write_inout]
    call write_v
    call write_h
    call write_q

!-------------------------------------
! [11.] WRITE FUNCTIONS
!-------------------------------------
[write_functions]
    call bycol_bND
    call bycol_qqtil
    call bycol_eqfunc
[bycol_bND]
    call spline
    splin
[bycol_qqtil]
[bycol_eqfunc]

!----------------------------------------
! [12.] SIMULATIONS AND DEFAULT EVENTS
!----------------------------------------
[simul_paths]
    call random_seed
    call random_number
    lip
    blip
    psi

    call report_stats
    call simulpaths_stats
    call defaultevents
    call haircuts_extensions(r_aux,del_aux)
    call slope_coeffs
    call split_by_default
    call final_stats

    call annualdata
    call report_stats
    call simulpaths_yr_stats
    call defaultevents
    call haircuts_extensions(r_aux,del_aux)
    call slope_coeffs
    call split_by_default
    call final_stats

    contains
    report_stats
    simulpaths_stats
    simulpaths_yr_stats
    defaultevents
    haircuts_extensions(r_aux,del_aux)
    slope_coeffs
            call Percentile
            call OLS
    OLS
    InvertMatrix
    split_by_default
            call Percentile
            call report_means
    report_means
    annualdata
    final_stats

!----------------------------------------
! IRF
!----------------------------------------
[stochsimul_IRF]
    use interp
    CALL SYSTEM_CLOCK
    CALL random_seed
    CALL SYSTEM_CLOCK
    CALL random_number
    call truncated_normal_ab_sample
    blip
    lininterp3

! -------------------------------------
! Calibration
! -------------------------------------
[calib_bobyqa_case1]
[calib_bobyqa_case2]
[calib_bobyqa_case3]
[calib_bobyqa_case4]
[calib_bobyqa_case5]
[calib_bobyqa_case6]
[calib_bobyqa_case7]
    use bobyqa_module
    call bobyqa

!*********************************************************
calfun.f90
    [calfun(nparam_dum,param_dum,val)]
        call initstuff
        call stat_distr
        call prices_iter
        call simul_paths
!*********************************************************

!*********************************************************
bobyqa.90
    module bobyqa_module
        [bobyqa]
!*********************************************************

!*********************************************************
interp.f90
    module interp
    <lip> [spline] <splint>
!*********************************************************

!*********************************************************
tauchen_mod.f90
    module tauchen_mod
    [tauchen]
!*********************************************************


!*********************************************************
! OUTPUT FILES
!*********************************************************
stat_distr.dat
transprob_nu.dat

!
!Interim policy functions:
!
agentND_fig.dat
DEF_fig.dat
DEF_barg_nu1_fig.dat
barg_nu1_ND_fig.dat
DEF_barg_nu2_fig.dat
barg_nu2_ND_fig.dat
H_thet0_fig.dat
H_thet1_fig.dat
Qdiff_fig.dat
qq_fig.dat

nu1_ND_temp.dat - show how participation constraint determines offers.
nu2_ND_temp.dat

!
! Final policy functions
!

[bycol_bND]
    call spline
    splin
[bycol_qqtil]
[bycol_eqfunc]

simulpaths.dat
